package com.qm.qmzs.controller;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.stream.StreamUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.setting.yaml.YamlUtil;
import com.qm.qmzs.conts.JdCont;
import com.qm.qmzs.util.DictToMapUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.yaml.snakeyaml.Yaml;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * @author zpc
 * @version 1.0
 * @description 抢苗controller
 * @create 2022/4/13 16:33
 */
@RestController
@Slf4j
@RequestMapping("ready")
public class QmController {

    @PostMapping("/go/{jdmc}")
    public String go(@PathVariable("jdmc")String jdmc) {
      log.info("开始进入抢苗 ---> " + LocalDateTimeUtil.format(LocalDateTime.now(),"yyyy-MM-dd HH:mm:ss"));
      if(jdmc.equals(JdCont.JD_BIJIASHAN)){
          JSONObject jsonObject = new JSONObject();
          jsonObject.set("doctorid",12);
          jsonObject.set("patientid",98848);
          jsonObject.set("recoredId",1);
          Map map = DictToMapUtil.toMap("bijiashanheader.yml");
          HttpResponse res = HttpRequest.post("https://www.0551cx.com/appointment/mobile/user/bookedPay")
                  .body(jsonObject.toString())
                  .addHeaders(map)
                  .execute();
          return res.body();
      }else if(jdmc.equals(JdCont.JD_WULIDUN)){

      }else if(jdmc.equals(JdCont.JD_DAOXIANGCUN)){
          Map map = DictToMapUtil.toMap("daoxiangcun.yml");
          HttpResponse res = HttpRequest.post("https://appoint.yihu.com/appoint/do/user/getUserInfo")
                  .addHeaders(map)
                  .execute();
          return res.body();
      }
      return "未知错误! ---> jdmc" + jdmc + ",时间 ---> " +  LocalDateTimeUtil.format(LocalDateTime.now(),"yyyy-MM-dd");
    }

}
